<template>
  <!--a-layout>
    <a-layout-header class="header">
      <div class="logo" />
      <a-menu
        theme="dark"
        mode="horizontal"
        v-model:selectedKeys="selectedKeys1"
        :style="{ lineHeight: '64px' }"
      >
        <a-menu-item key="1">超级管理员</a-menu-item>
      </a-menu>
    </a-layout-header>
    <a-layout-content style="padding: 0 50px">
      <a-breadcrumb style="margin: 16px 0">
        <a-breadcrumb-item>Home</a-breadcrumb-item>
        <a-breadcrumb-item>List</a-breadcrumb-item>
      </a-breadcrumb>
      <a-layout style="padding: 24px 0; background: #fff">
        <a-layout-sider width="200" style="background: #fff">
          <a-menu
            mode="inline"
            v-model:selectedKeys="selectedKeys2"
            v-model:openKeys="openKeys"
            style="height: 100%"
          >
            <a-sub-menu key="sub1">
              <template #title>
                <span>
                  <user-outlined />
                  后台用户
                </span>
              </template>
              <a-menu-item key="1" @click="manage">后台用户管理</a-menu-item>
              <a-menu-item key="2" @click="apply">后台用户申请</a-menu-item>
            </a-sub-menu>
            <a-sub-menu key="sub2">
              <template #title>
                <span>
                  <laptop-outlined />
                  个人中心
                </span>
              </template>
              <a-menu-item key="3" @click="own">个人信息</a-menu-item>
            </a-sub-menu>
          </a-menu>
        </a-layout-sider>
        <a-layout-content :style="{ padding: '0 24px', minHeight: '500px' }">
          <router-view></router-view>
        </a-layout-content>
      </a-layout>
    </a-layout-content>
    <a-layout-footer style="text-align: center">
      Community ©2021 Designed by ZHAO YU
    </a-layout-footer>
  </a-layout-->
  <div>
    <a-layout>
      <a-layout-header class="header">
        <a-menu
          theme="dark"
          mode="horizontal"
          :style="{ lineHeight: '64px' }"
          v-model:selectedKeys="selectedKeys1"
          @select="selectMenu"
        >
          <a-menu-item v-for="ele in keyMap" :key="ele.key">{{
            ele.value
          }}</a-menu-item>
          <a-menu-item :key="'/buser/login'" style="float: right" @click="exit">
            退出
          </a-menu-item>
        </a-menu>
      </a-layout-header>
      <a-layout-content style="padding: 0 50px">
        <a-breadcrumb style="margin: 16px 0">
          <a-breadcrumb-item>主界面</a-breadcrumb-item>
          <a-breadcrumb-item>{{ selectedValue1 }}</a-breadcrumb-item>
        </a-breadcrumb>

        <a-layout style="padding: 24px 0; background: #fff">
          <a-layout-content :style="{ padding: '0 24px', minHeight: '500px' }">
            <router-view></router-view>
          </a-layout-content>
        </a-layout>
      </a-layout-content>
    </a-layout>
  </div>
</template>
<script setup>
import { useRouter } from "vue-router";
import { get, del, post, tip, removeLocalBToken } from "@/common";
import { ref } from "vue";

const router = useRouter();
const selectedKeys1 = ref();
const selectedValue1 = ref("");
const keyMap = ref([
  { key: "/buser/articlemanage", value: "文章管理" },
  { key: "/buser/usermanage", value: "用户管理" },
  { key: "/buser/queuemanage", value: "队列管理" },
]);
const selectMenu = ({ item, key, selectedKeys }) => {
  router.push({ path: key });
  keyMap.value.forEach((element) => {
    if (element.key == key) {
      if (key == "/buser/home/mainview") {
        selectedValue1.value = "";
      } else {
        selectedValue1.value = element.value;
      }
      return;
    }
  });
};

const infoData = ref({});
const getInfo = () => {
  get("/buser/home/curr-user").then((res) => {
    infoData.value = res.data;
  });
};
const exit = () => {
  del("/buser/home/exit").then((res) => {
    tip.success("您已成功退出系统，请重新登录！");
    removeLocalBToken();
    router.push({ path: "/buser/login" });
    infoData.value = {};
  });
};
</script>

<style>
.ant-col-4 {
  background: #ffffff;
  height: 100%;
}
.ant-col-16 {
  background: #ffffff;
  height: 100%;
  min-height: 100vh;
  box-shadow: rgb(182, 182, 182) 0px 0px 2px;
}

#components-layout-demo-top-side .logo {
  float: left;
  width: 120px;
  height: 31px;
  margin: 16px 24px 16px 0;
  background: rgba(255, 255, 255, 0.3);
}
.ant-row-rtl #components-layout-demo-top-side .logo {
  float: right;
  margin: 16px 0 16px 24px;
}

.site-layout-background {
  background: #fff;
}
</style>
